<template>
	<view>
		<form>
			<view class="cu-form-group margin-top">
				<view class="title">养殖仓编号</view>
				<input maxlength="10" v-model="editorWarehouseNo" name="input" style="text-align: right; margin-right: 20rpx;"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">养殖仓面积</view>
				<input maxlength="6" v-model="editorArea" type="digit" name="input" style="text-align: right; margin-right: 20rpx;"></input>
				<text style="font-size: 34rpx;">m²</text>
			</view>
			<view class="cu-form-group">
				<view class="title">养殖数量</view>
				<input maxlength="8" v-model="editorcount" type="number" name="input" style="text-align: right; margin-right: 20rpx;"></input>
				<text style="font-size: 34rpx; margin-right: 10rpx;">头</text>
			</view>
			<view class="cu-form-group margin-top">
				<view class="title">养殖仓负责人</view>
				<input maxlength="6" v-model="editorwarehousePerson" name="input" style="text-align: right; margin-right: 20rpx;"></input>
			</view>
			<view class="cu-form-group">
				<view class="title">负责人联系电话</view>
				<input maxlength="11" v-model="editorphone" name="input" style="text-align: right; margin-right: 20rpx;"></input>
			</view>
		</form>
	</view>
</template>

<script>
	export default {
		data () {
			return {
				//上个页面传来的数据
				editorWarehouseNo: '',
				editorcount: '',
				editorwarehousePerson: '',
				editorphone: '',
				editorArea: '',
				editorID: ''
			}
		},
		onNavigationBarButtonTap() {
			this.save()
		},
		methods: {
			save () {
				var mobileReg=/^1[34578]\d{9}$/
				//console.log(this.User.token)
				if(this.editorWarehouseNo.toString() === ""){
					uni.showToast({
						title:"请填写正确的养殖仓编号",
						icon: "none"
					})
					return;
				}
				else if(this.editorArea.toString() === "" || this.editorArea <= 0){
					uni.showToast({
						title:"请填写正确的养殖仓面积",
						icon: "none"
					})
					return;
				}
				else if(this.editorcount.toString().indexOf(".") !== -1 || this.editorcount.toString() === ""){
					uni.showToast({
						title:"请填写正确的养殖仓数量（不能含有小数）",
						icon: "none"
					})
					return;
				}
				else if(this.editorwarehousePerson.toString() === ""){
					uni.showToast({
						title:"请输入养殖仓负责人",
						icon: "none"
					})
					return;
				}
				else if(!mobileReg.test(this.editorphone)){
					uni.showToast({
						title:"请填写正确的负责人联系电话",
						icon: "none"
					})
					return;
				}
				else{
					uni.request({
						url: this.confige.webUrl+'/livestock/updWarehouse',
						data: {
							warehouse_serial_number: this.editorWarehouseNo,
							warehouse_area: this.editorArea,
							warehouse_number: this.editorcount,
							warehouse_phone: this.editorphone,
							warehouse_admin_name: this.editorwarehousePerson,
							farm_id: this.User.userInfo.farm_id,
							farm_name: this.User.userInfo.farm_name,
							warehouse_faeces_id: 99,
							warehouse_faeces_id: 100,
							warehouse_id: this.editorID
						},
						method:"POST",
						header: {
							"X-Token":this.User.token
						},
						success: (res) => {
							console.log(res)
							if(res.data.code == 200){
								uni.showModal({
									title: "提示",
									showCancel: false,
									content: "修改成功",
									success: (res) => {
										if(res.confirm){
											uni.navigateBack({
												delta: 1
											})
										}
									}
								})	
							}
							else if(res.data.code == 400) {
								uni.showModal({
									title: "提示",
									showCancel: false,
									content: res.data.message
								})
							}
						}
						
					})
					console.log('手机：' + this.editorphone+'--负责人：' + this.editorwarehousePerson+'--编号：' +this.editorWarehouseNo+'--数量：' +this.editorcount+'--面积：' +this.editorArea)
				}	
				
			}
		},
		onLoad(option) {
			this.editorWarehouseNo = option.editorWarehouseNo
			this.editorcount = option.editorcount
			this.editorwarehousePerson = option.editorwarehousePerson
			this.editorphone = option.editorphone
			this.editorArea = option.editorArea
			this.editorID = option.editorID
		}
	}
</script>

<style lang="less">
	@import '../../../common/main.css';
	
	page {
		background: #EEEEEE;
	}
	
	.save {
		width: 710rpx;
		height: 80rpx;
		position: fixed;
		bottom: 30rpx;
	}
	
	.save button {
		background-color: #4AC997;
		color: white;
		font-weight: bold;
		border-radius: 60rpx;
		margin-left: 40rpx;
		height: 80rpx;
	}
</style>
